package com.hndzyu.yd.ui;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.hndzyu.yd.R;
import com.hndzyu.yd.bean.NEW;
import com.hndzyu.yd.url.Path;

import java.util.List;

/**
 * Created by zz9527 on 2018/12/13.
 */
public class NewAdapter extends BaseAdapter {
    private final LayoutInflater inflater;
    private  Context context;
    private List<NEW.DataBean> list;
    public NewAdapter(Context context, List<NEW.DataBean> list) {
        this.list=list;
        this.context=context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public NEW.DataBean getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHold hold;
        if (view==null){
            view=inflater.inflate(R.layout.adapter_new,null);
            hold=new ViewHold();
            hold.iv=view.findViewById(R.id.iv);
            hold.title=view.findViewById(R.id.title);
            hold.intro=view.findViewById(R.id.intro);
            hold.price=view.findViewById(R.id.price);
            view.setTag(hold);
        }else {
            hold= (ViewHold) view.getTag();
        }
        NEW.DataBean dataBean = list.get(i);
        hold.title.setText(dataBean.getTitle());
        Glide.with(context).load(Path.img(dataBean.getLogo())).apply(new RequestOptions().error(R.mipmap.logo)).into(hold.iv);
        if ("".equals(dataBean.getScon())){
            hold.intro.setText("完成快速任务获得奖励");
        }else {
            hold.intro.setText(dataBean.getScon());
        }
        hold.price.setText("+"+dataBean.getMoney()+"元");
        return view;
    }
    class ViewHold{
        ImageView  iv;
        TextView title;
        TextView intro;
        TextView price;
    }

}
